<?php
$max_rows = '20';
$hoy = strftime('%Y-%m-%d');
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"

$user_now = '';


function fmt($val){
return number_format($val,2);
}
function myRound($valor){
$float_redondeado=round($valor * 100) / 100; 
   return $float_redondeado; 
}


function isZeros($val,$txt){
	if ($val != 0){
	return $txt;
	}
	else {
	return '';
	}	
}

function doEcho($msg){
//	echo ("<span class=''>$msg</span>");
}

function getVal($nom){
	if (isset($_POST[$nom])){
	return $_POST[$nom];
	}
	else {
	return '';
	}
}

function isNull($val,$txt){
	if (trim($val) != ''){
	return $txt;
	}
	else {
	return '';
	}	
}

function isEmpty($val){
	if (trim($val)== ''){
	return true;
	}
	return false;
}

session_cache_expire(60);
session_start();
if (isset($_SESSION['user'])){
$user_now = $_SESSION['user']['UserID'];
$usr_ctr = $_SESSION['user']['CentroID'];
$usr_alm = $_SESSION['user']['AlmacenID'];
$usr_mul = $_SESSION['user']['UserMulti'];
}
if (!isset($_SESSION['user']) && !isset($_POST['login'])){
echo '<script type="text/javascript">showError("No existe sesion Activa\nProceso Cancelado.");loadPage("login.php");</script>';
exit;
}

//session_unset();

/*
$hostname_TOYOCON = "localhost";
$database_TOYOCON = "toyocar2";
$username_TOYOCON = "root";
$password_TOYOCON = "root";
*/

$hostname_TOYOCON = "toyocar3.db.10341326.hostedresource.com";
$database_TOYOCON = "toyocar3";
$username_TOYOCON = "toyocar3";
$password_TOYOCON = "Lpo123qwe!";

//$db = mysql_connect($hostname_TOYOCON, $username_TOYOCON, $password_TOYOCON) or trigger_error(mysql_error(),E_USER_ERROR); 
//mysql_select_db($database_TOYOCON,$db);
//$db = mysql_connect($hostname_TOYOCON, $username_TOYOCON, $password_TOYOCON) or trigger_error(mysql_error(),E_USER_ERROR); 
$mysqli = new mysqli($hostname_TOYOCON, $username_TOYOCON, $password_TOYOCON,$database_TOYOCON) or trigger_error(mysql_error(),E_USER_ERROR); 

function showTable($mysqli,$sql,$heads,$row_fields,$tbl_attr='',$pag=1) {
	$max_rows = 20;
/*	if ($pag == 1){
	$sql = $sql." limit 0,".$max_rows;
	}
	else {
	$ini = ((($pag-1)*$max_rows) + 1);
	$sql = $sql." limit ".$ini."," .$max_rows; 	
	}*/
	$resultSet = $mysqli->query($sql);
   echo "<table width='100%' border='1' rules='all' ".$tbl_attr."><thead><tr>";
   // Get fields' name and print table header row
   $fields = '';
   if (!$heads == ''){
      foreach ($heads as $head) {
      echo "<th>".$head."</th>";
   	  }
   }
   else {
   $fields = $resultSet->fetch_fields();  // Get all fields
      foreach ($fields as $field) {
      echo "<th>{$field->name}</th>";
   		}
   }
   

   echo '</tr></thead>';
 	echo "<tbody>";
   // Fetch each row and print table detail row
   $c_rows = 0;
   
   for ($r = 0; $r < $resultSet->num_rows; ++$r) {
      $d_row = $resultSet->fetch_assoc();  // fetch current row into an associative array
      echo '<tr>';
      foreach ($row_fields as $row) {
         echo "<td>".$d_row[$row]."</td>";
      }
      echo '</tr>';	  
	  $c_rows += 1;
	  if ($c_rows == $max_rows){
	  break;
	  }
   }
   
   
   echo '</tbody>';
   echo '<tfoot><tr><td colspan="'.count($heads).'"></td></tr></tfoot>';
   echo '</table>';
}

/*
$res = $mysqli->multi_query("call sp_addProveedor('prueba','RAZSOC prueba','12345678','Jr. prueba 23','010101','USER01',@newnro);select @newnro;");

if( $res ) {
  $results = 0;
  do {
    if ($result = $mysqli->store_result()) {
      printf( "<b>Result #%u</b>:<br/>", ++$results );
      while( $row = $result->fetch_row() ) {
        foreach( $row as $cell ) echo $cell, "&nbsp;";
      }
      $result->close();
      if( $mysqli->more_results() ) echo "<br/>";
    }
  } while( $mysqli->next_result() );
}
else {
echo ('error');
}
$mysqli->close();
*/
?>